﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

using C1.Phone.Chart;
using System.Text;

namespace ControlExplorer.Controls.Chart
{
    public partial class Gallery
        : UserControl, IExposeApplicationBarItems
    {
        List<ApplicationBarMenuItem> _menuItems = new List<ApplicationBarMenuItem>();
        SampleData sampleData;

        public Gallery()
        {
            InitializeComponent();

            sampleData = new SampleData();
            c1chart.BeginUpdate();
            c1chart.Data = sampleData.DefaultData;
            c1chart.Data.LoadAnimation = AnimationHelper.CreateAnimation(AnimationTransform.Scale, AnimationOrigin.Center, Easing.CubicEase, true);
            c1chart.EndUpdate();

            foreach (var value in C1.Phone.Extensions.GetEnumValues<ChartType>(typeof(ChartType)))
            {
                var mitem = new ApplicationBarMenuItem()
                {
                    Text = Utils.SeparateWords(value.ToString())
                };
                mitem.Click += mitem_Click;
                _menuItems.Add(mitem);
            }
  
        }


        void mitem_Click(object sender, EventArgs e)
        {
            var menuItem = (ApplicationBarMenuItem)sender;
            var chartType = (ChartType)_menuItems.IndexOf(menuItem);
            if (chartType == ChartType.HighLowOpenClose || chartType == ChartType.Candle)
                c1chart.Data = sampleData.FinancialData;
            else if (chartType == ChartType.Bubble)
                c1chart.Data = sampleData.BubbleData;
            else if (chartType == ChartType.Gantt)
                c1chart.Data = sampleData.GanttData;
            else
                c1chart.Data = sampleData.DefaultData;
            c1chart.ChartType = chartType;
        }


        #region IExposeApplicationBarItems Members

        public IEnumerable<IApplicationBarMenuItem> ApplicationBarItems
        {
            get 
            {
                return _menuItems.Cast<IApplicationBarMenuItem>();
            }
        }

        #endregion
    }
}